package com.own.component.util.excel.util.write.style.item;

import com.own.component.util.excel.util.write.style.base.AbstractStyleFunction;
import org.apache.poi.ss.usermodel.BorderStyle;
import org.apache.poi.ss.usermodel.CellStyle;

/**
 * StyleItemBorderStyle
 *
 * @author chenxueli
 * @date 2023-05-11 16:00:00
 */
public class StyleItemBorderStyle extends AbstractStyleFunction<BorderStyle> {

    public static StyleItemBorderStyle NONE = new StyleItemBorderStyle(BorderStyle.NONE);
    public static StyleItemBorderStyle THIN = new StyleItemBorderStyle(BorderStyle.THIN);
    public static StyleItemBorderStyle MEDIUM = new StyleItemBorderStyle(BorderStyle.MEDIUM);
    public static StyleItemBorderStyle DASHED = new StyleItemBorderStyle(BorderStyle.DASHED);
    public static StyleItemBorderStyle DOTTED = new StyleItemBorderStyle(BorderStyle.DOTTED);
    public static StyleItemBorderStyle THICK = new StyleItemBorderStyle(BorderStyle.THICK);
    public static StyleItemBorderStyle DOUBLE = new StyleItemBorderStyle(BorderStyle.DOUBLE);
    public static StyleItemBorderStyle HAIR = new StyleItemBorderStyle(BorderStyle.HAIR);
    public static StyleItemBorderStyle MEDIUM_DASHED = new StyleItemBorderStyle(BorderStyle.MEDIUM_DASHED);
    public static StyleItemBorderStyle DASH_DOT = new StyleItemBorderStyle(BorderStyle.DASH_DOT);
    public static StyleItemBorderStyle MEDIUM_DASH_DOT = new StyleItemBorderStyle(BorderStyle.MEDIUM_DASH_DOT);
    public static StyleItemBorderStyle DASH_DOT_DOT = new StyleItemBorderStyle(BorderStyle.DASH_DOT_DOT);
    public static StyleItemBorderStyle MEDIUM_DASH_DOT_DOT = new StyleItemBorderStyle(BorderStyle.MEDIUM_DASH_DOT_DOT);
    public static StyleItemBorderStyle SLANTED_DASH_DOT = new StyleItemBorderStyle(BorderStyle.SLANTED_DASH_DOT);

    private final BorderStyle top;
    private final BorderStyle bottom;
    private final BorderStyle left;
    private final BorderStyle right;

    public StyleItemBorderStyle(BorderStyle item) {
        this(item, item, item, item);
    }

    public StyleItemBorderStyle(BorderStyle topBottom, BorderStyle rightLeft) {
        this(topBottom, rightLeft, topBottom, rightLeft);
    }

    public StyleItemBorderStyle(BorderStyle top, BorderStyle right, BorderStyle bottom, BorderStyle left) {
        super(null);
        this.top = top;
        this.right = right;
        this.bottom = bottom;
        this.left = left;
    }

    /**
     * 使用样式
     *
     * @param style 样式
     */
    @Override
    public void apply(CellStyle style) {
        if (top != null) {
            style.setBorderTop(top);
        }
        if (bottom != null) {
            style.setBorderBottom(bottom);
        }
        if (left != null) {
            style.setBorderLeft(left);
        }
        if (right != null) {
            style.setBorderRight(right);
        }
    }

}
